<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/blog/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://guodh.gitee.io/blog').hostname,
    root: '/blog/',
    scheme: 'Pisces',
    version: '7.7.1',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="曾经以为自己对于面向对象还是足够了解的。不就是一个理念嘛，还是Java所一直比比的，就是一些很low的概念，根本不会对我的代码产生任务影响。然而直到这次Code Review才了解到面向对象是一个很重要的概念。 面向对象是现在程序员所必须掌握的重要理念之一，对于面向对象理解程度的深浅直接影响每个程序员是否能否成为一个合格的架构师。那么，就让我们一起从历史的开始讲起。">
<meta property="og:type" content="article">
<meta property="og:title" content="面向对象">
<meta property="og:url" content="https://guodh.gitee.io/blog/2018/08/26/2018/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/index.html">
<meta property="og:site_name" content="蛋蛋的小屋">
<meta property="og:description" content="曾经以为自己对于面向对象还是足够了解的。不就是一个理念嘛，还是Java所一直比比的，就是一些很low的概念，根本不会对我的代码产生任务影响。然而直到这次Code Review才了解到面向对象是一个很重要的概念。 面向对象是现在程序员所必须掌握的重要理念之一，对于面向对象理解程度的深浅直接影响每个程序员是否能否成为一个合格的架构师。那么，就让我们一起从历史的开始讲起。">
<meta property="og:locale">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/javap.png">
<meta property="article:published_time" content="2018-08-26T09:26:57.000Z">
<meta property="article:modified_time" content="2018-09-09T02:19:00.000Z">
<meta property="article:author" content="RunningEgg">
<meta property="article:tag" content="技术">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://olwr1lamu.qnssl.com/javap.png">

<link rel="canonical" href="https://guodh.gitee.io/blog/2018/08/26/2018/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>面向对象 | 蛋蛋的小屋</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">蛋蛋的小屋</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">来了就看看吧，没有刀剑只有故事</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-fw fa-user"></i>About</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>

  </li>
        <li class="menu-item menu-item-book">

    <a href="/blog/book/" rel="section"><i class="fa fa-fw fa-archive"></i>book</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="https://guodh.gitee.io/blog/2018/08/26/2018/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="RunningEgg">
      <meta itemprop="description" content="写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="蛋蛋的小屋">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          面向对象
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2018-08-26 17:26:57" itemprop="dateCreated datePublished" datetime="2018-08-26T17:26:57+08:00">2018-08-26</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2018-09-09 10:19:00" itemprop="dateModified" datetime="2018-09-09T10:19:00+08:00">2018-09-09</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>曾经以为自己对于面向对象还是足够了解的。不就是一个理念嘛，还是Java所一直比比的，就是一些很low的概念，根本不会对我的代码产生任务影响。然而直到这次Code Review才了解到面向对象是一个很重要的概念。</p>
<p>面向对象是现在程序员所必须掌握的重要理念之一，对于面向对象理解程度的深浅直接影响每个程序员是否能否成为一个合格的架构师。那么，就让我们一起从历史的开始讲起。</p>
<a id="more"></a>

<h2 id="软件开发的历史"><a href="#软件开发的历史" class="headerlink" title="软件开发的历史"></a>软件开发的历史</h2><p>凡事都是有因有果，面向对象也不是凭空产生出来，而是人们遭受了软件开发的各种打击才产生出来的。简单的来讲，就是从二进制，汇编，面向过程，面向对象发生演变。</p>
<h3 id="二进制编程"><a href="#二进制编程" class="headerlink" title="二进制编程"></a>二进制编程</h3><p>01，这两个数字在程序员心中永远是最神圣的，然而如果让一个程序员用01给你编一个软件的话，估计是直接拿刀出来砍人了。</p>
<h3 id="汇编语言"><a href="#汇编语言" class="headerlink" title="汇编语言"></a>汇编语言</h3><p>当计算机的性能逐渐提升，能够存放下更多指令空间的时候，便诞生了汇编语言。MOVE，ADD这些简单并且是最基础的命令，构建起了我们的软件。当然，<br>在Java的世界，你可以使用javap工具来查看将class文件反汇编之后的情况。如下图：</p>
<img src="https://olwr1lamu.qnssl.com/javap.png" width="100%" height="100%" alt="javap结果"/>

<h3 id="面向过程"><a href="#面向过程" class="headerlink" title="面向过程"></a>面向过程</h3><p>随着计算机计算能力的继续发展，人力资源成为软件发展的瓶颈的时候，高级语言也就随着时代的需要而诞生。C语言是其中最为出名的，即使在今天也和Java不相上下。<br>举个例子，</p>
<p>面向过程：</p>
<ol>
<li>向右移动 (人物1)</li>
<li>攻击 (人物1)</li>
<li>死亡 (敌人)</li>
<li>购买物品 (人物1)</li>
</ol>
<p>面向对象：</p>
<ol>
<li>人物1.向右移动</li>
<li>人物1.攻击</li>
<li>敌人.死亡</li>
<li>人物1.购买物品</li>
</ol>
<p>总体而言，面向过程采用了“自顶而下，逐步细化，模块化”的思想来指导开发，将软件的复杂度控制在一定范围中。</p>
<h3 id="面向对象"><a href="#面向对象" class="headerlink" title="面向对象"></a>面向对象</h3><p>讲了这么多，终于到了面向对象。如果说面向过程是编程语言发展的产物，那么面向对象就是软件行业发展的产物。我们都知道软件开发流程从以往的瀑布式开发，到如今的敏捷式<br>开发，都是为了适应软件行业的发展——快速变化。</p>
<p>与面向过程一步一步开发不同的是，面向对象封装起了对象，将每一步的过程成功隔离开来。如果说这些是一成不变的，那把代码封装在对象之中确实很傻。但是如果说，每一步都是会发生变化，都有可能重构。那么面向对象的真正作用才发挥的出来。</p>
<h2 id="面向编程三大特点"><a href="#面向编程三大特点" class="headerlink" title="面向编程三大特点"></a>面向编程三大特点</h2><p>封装、继承、多态</p>
<h2 id="设计原则-and-设计模式"><a href="#设计原则-and-设计模式" class="headerlink" title="设计原则 and 设计模式"></a>设计原则 and 设计模式</h2><p>SOLID 设计原则</p>
<p>Single Responsibility Principle<br>Open/Close Principle<br>Liskov Substitution Principle<br>Interface Segregation Principle<br>Dependency Inversion Principle</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/%E6%8A%80%E6%9C%AF/" rel="tag"># 技术</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2018/08/05/2018/%E5%B7%A5%E5%85%B7%E7%AE%B1/" rel="prev" title="工具箱">
      <i class="fa fa-chevron-left"></i> 工具箱
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2018/09/08/2018/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BA%E5%B7%A5%E5%8E%82%E6%A8%A1%E5%BC%8F/" rel="next" title="深入浅出工厂模式">
      深入浅出工厂模式 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91%E7%9A%84%E5%8E%86%E5%8F%B2"><span class="nav-number">1.</span> <span class="nav-text">软件开发的历史</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BA%8C%E8%BF%9B%E5%88%B6%E7%BC%96%E7%A8%8B"><span class="nav-number">1.1.</span> <span class="nav-text">二进制编程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80"><span class="nav-number">1.2.</span> <span class="nav-text">汇编语言</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%9D%A2%E5%90%91%E8%BF%87%E7%A8%8B"><span class="nav-number">1.3.</span> <span class="nav-text">面向过程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1"><span class="nav-number">1.4.</span> <span class="nav-text">面向对象</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%9D%A2%E5%90%91%E7%BC%96%E7%A8%8B%E4%B8%89%E5%A4%A7%E7%89%B9%E7%82%B9"><span class="nav-number">2.</span> <span class="nav-text">面向编程三大特点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AE%BE%E8%AE%A1%E5%8E%9F%E5%88%99-and-%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F"><span class="nav-number">3.</span> <span class="nav-text">设计原则 and 设计模式</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">RunningEgg</p>
  <div class="site-description" itemprop="description">写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">89</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">tags</span>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="mailto:guodh_1@163.com" title="E-Mail → mailto:guodh_1@163.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">RunningEgg</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> v5.3.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">Theme – <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.7.1
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  















  

  

</body>
</html>
